# Create your views here.
from django.shortcuts import render_to_response
from models import Album
from models import Photo


def index(request):
	"""
	   The main intro page.  In this first release, it creates
	   a list of albumbs with their respective thumbnails
	   as links to the gallery pages for them
	"""
	try:
		albums = Album.objects.all()
		albums.url='/album/'
		albums.first=albums[0]
	except:
		albums=None
		
	return render_to_response('photodistro/index.html',{'albums':albums,'is_logged_in':request.user.is_authenticated()})

def album (request,id=1):
	"""
	   renders a photo album of a particular id
	"""
	try:
		photos = Photo.objects.filter(album=id)
		album = Album.objects.get(id=id)
		photos.album=album
	except:
		photos=None
	return render_to_response('photodistro/gallery.html',{'photos':photos,'is_logged_in':request.user.is_authenticated()})
